package gdut.imis;

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

/**
 * @Description
 * @Author JiaFu
 * @Date 2024/1/27 17:32
 */
@MapperScan("gdut.imis.mapper")
@SpringBootApplication
public class ElasticsearchApp {
    public static void main(String[] args) {
        SpringApplication.run(ElasticsearchApp.class,args);
    }
    @Bean
    public RestHighLevelClient get(){
        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials("elastic","5247aishiqiAI!"));
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(
                RestClient.builder(HttpHost.create("http://112.74.86.144:9200"))
                        .setHttpClientConfigCallback(httpClientBuilder -> {
                            httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                            return httpClientBuilder;
                        })
        );//阿里云
        return restHighLevelClient;
    }
}
